<template>
<div class="content">
  <div class="content-b">
    <!-- <img class="img" src="../assets/bg1.jpg"/> -->
  </div>
  <div class="content-t">
    <el-container> 
      <el-header style="height:100px;">
        <!-- <img src="../assets/logo.png"/> -->
        <div>散乱污企业监测系统</div>
      </el-header>
      <el-main>
        <div class="name">北辰散乱污企业监测系统</div>
        <el-form :model="loginForm"
          ref="loginForm"
          :rules="rules"
          status-icon
          class="login-form">
          <el-form-item label=""
            prop="userName">
            <el-input v-model="loginForm.userName"
              :placeholder="loginForm.placeholderName"
              auto-complete="off"
              class="login-input"></el-input>
          </el-form-item>
          <el-form-item label=""
            prop="userPass">
            <el-input type="password"
              v-model="loginForm.userPass"
              :placeholder="loginForm.placeholderPass"
              auto-complete="off"
              @keydown.enter.native="userLogin('loginForm')"
              class="login-input"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"
              @click="userLogin('loginForm')"
              class="login-btn">登录</el-button>
          </el-form-item>
        </el-form>
      </el-main>
      <el-footer style="height:30px">北辰环保局&nbsp;&nbsp;&nbsp;版权所有Copyright © @2018 All Right Reserved</el-footer>
    </el-container>
  </div>
</div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    const validateUserName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入正确的用户名'))
      } else {
        callback()
      }
    }
    const validateUserPass = (rule, value, callback) => {
      if (value.length < 5) {
        callback(new Error('密码不能小于5位'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        placeholderName: '用户名',
        placeholderPass: '密码',
        userName: '',
        userPass: ''
      },
      rules: {
        userName: [
          { required: true, validator: validateUserName, trigger: 'blur' }
        ],
        userPass: [
          { required: true, validator: validateUserPass, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    userLogin(loginForm) {
      this.$refs[loginForm].validate(valid => {
        if (valid) {
          const name = this.loginForm.userName
          const pass = this.loginForm.userPass
          const router = this.$router
          const route = this.$route
          if(name === "admin" && pass === "123456"){
            router.push(route.query.redirect || '/index')
          }
        } 
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.content,.content-b{
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.content{
  position: relative;
}
.content-t{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.img{
 width: 100%;
 height: 100%;
 
}
.el-container{
  height: 100%;
  overflow: hidden;
}
.el-header{
  border-bottom: 2px solid #dddddd;
  padding: 20px 0;
}
.el-form{
  max-width: 350px;
  margin: 20px auto 0;
  border: 3px solid #cbcccc;
  padding: 50px;
}
.el-header img,.el-header div{
  float: left;
}
.el-header div{
  font-size: 24px;
  line-height: 60px;
}
.el-form{
  max-width: 350px;
  margin: 20px auto 0 auto;
  border: 3px solid #cbcccc;
  padding: 50px;
}
.el-button{
  width: 100%;
}
.el-footer{
  font-size: 12px;
  text-align: center;
  color: #f3f8fc;
}
.name{
  text-align: center;
  font-size: 50px;
  margin-top: 120px;
}
</style>
